<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$return['setting']=$this->plugin_setting('basic');
if($_RQ['op']=='main' || $_RQ['op']=='plant'){
	$plant_id=intval($_RQ['id']);
	if(!$plant_id){
		exi('请选择订单！','error','/myplant/');
	}
	$plant=pdo_get('jy_farmer_plant',array('uniacid'=>$_SESSION['uniacid'],'id'=>$plant_id));
	$return['plant']=$plant;
	$return['params']=array('plant_id'=>$plant_id);
	$return['list']=array();
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	$params['plant_id']=intval($_RQ['plant_id']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_farmer_plant_log',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$plant=pdo_get('jy_farmer_plant',array('uniacid'=>$_SESSION['uniacid'],'id'=>$params['plant_id']));
		foreach($list as &$item){
			$seed_id=pdo_getcolumn('jy_farmer_myseed',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['myseed_id']),'seed_id');
			$item['seed']=pdo_get('jy_farmer_seed',array('uniacid'=>$_SESSION['uniacid'],'id'=>$seed_id));
			$item['seed']['image']=tomedia($item['seed']['image']);
			$totype=pdo_getcolumn('jy_farmer_worker_log',array('createtime >'=>$daytime,'pid'=>$item['id'],'totype'=>0,'type'=>1,'uniacid'=>$_SESSION['uniacid']),'id');
			if($totype){
				$item['totype0']=1;
			}
			$totype=pdo_getcolumn('jy_farmer_worker_log',array('createtime >'=>$daytime,'pid'=>$item['id'],'totype'=>1,'type'=>1,'uniacid'=>$_SESSION['uniacid']),'id');
			if($totype){
				$item['totype1']=1;
			}
			$totype=pdo_getcolumn('jy_farmer_worker_log',array('createtime >'=>$daytime,'pid'=>$item['id'],'totype'=>2,'type'=>1,'uniacid'=>$_SESSION['uniacid']),'id');
			if($totype){
				$item['totype2']=1;
			}
			$totype=pdo_getcolumn('jy_farmer_worker_log',array('createtime >'=>$daytime,'pid'=>$item['id'],'totype'=>3,'type'=>1,'uniacid'=>$_SESSION['uniacid']),'id');
			if($totype){
				$item['totype3']=1;
			}
			if($item['seed']['shouyue']==$month && ($item['status']==1 || $item['status']==2)){
				$item['isshou']=1;
			}
			if($item['status']==4){
				$item['shoufee']=$item['seed']['oneprice']*$item['shoukg'];
			}
			$shoudaytime=$item['seed']['growtime']*24*3600+$item['createtime'];
			$item['seed']['shouday']=date('Y-m-d',$shoudaytime);
			if($shoudaytime<time() && $item['status']==2){
				$item['isshou']=1;
			}
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='water'){
	$plant_id=$_RQ['id'];
	$isarea=pdo_getsum('jy_farmer_plant_log',array('uniacid'=>$_SESSION['uniacid'],'plant_id'=>$plant_id),'plantarea');
	if($isarea<=0){
		exi('该地还未种植任何作物！操作失败！','error');	
	}
	exi('将立即通知管理员浇水');	
}

if($_RQ['op']=='weed'){
	$plant_id=$_RQ['id'];
	$isarea=pdo_getsum('jy_farmer_plant_log',array('uniacid'=>$_SESSION['uniacid'],'plant_id'=>$plant_id),'plantarea');
	if($isarea<=0){
		exi('该地还未种植任何作物！操作失败！','error');	
	}
	exi('将立即通知管理员除虫');	
}
if($_RQ['op']=='worm'){
	$plant_id=$_RQ['id'];
	$isarea=pdo_getsum('jy_farmer_plant_log',array('uniacid'=>$_SESSION['uniacid'],'plant_id'=>$plant_id),'plantarea');
	if($isarea<=0){
		exi('该地还未种植任何作物！操作失败！','error');	
	}
	exi('将立即通知管理员除草');	
}
if($_RQ['op']=='shifei'){
	$plant_id=$_RQ['id'];
	$isarea=pdo_getsum('jy_farmer_plant_log',array('uniacid'=>$_SESSION['uniacid'],'plant_id'=>$plant_id),'plantarea');
	if($isarea<=0){
		exi('该地还未种植任何作物！操作失败！','error');	
	}
	exi('将立即通知管理员施肥');	
}
